clear 
est clear

* seeds for reproducibility
set seed 4353443
set sortseed 3534547

**********************************************************************
*** Plot the CDF of the PHQ and GHQ scores 
**********************************************************************

******* Compare everyone
use "${data}/Analysis_wide.dta", clear
distinct block club
keep phq8_score? ghq12_score? w? block cr_id club treat 
reshape long phq8_score ghq12_score w, i(block cr_id club treat ) j(round)

forvalues r=1/3 {
	if `r'==1 {
		local round = "Rapid Resurvey"
	} 
	else if `r'==2 {
		local round = "Midline"
	} 
	else if `r'==3 {
		local round = "Endline"
	}
	**** PHQ
	distplot phq8_score [aw=w] if round==`r', over(treat) ///
		graphregion(color(white)) legend(rows(1) pos(6)) lc(green red blue) ///
		title("PHQ-8 Score at `round'") 
	graph export "${figures}/cdf_phq8_r`r'.png", replace 
	*** GHQ
	distplot ghq12_score [aw=w] if round==`r', over(treat) ///
		graphregion(color(white)) legend(rows(1) pos(6)) lc(green red blue) ///
		title("GHQ-12 Score at `round'")
	graph export "${figures}/cdf_ghq12_r`r'.png", replace 
}

 

******* Compare therapy and control
use "${data}/Analysis_wide.dta", clear
distinct block club
gen treat_any = treat != 0 
keep phq8_score? ghq12_score? w? block cr_id club treat_ther treat 
reshape long phq8_score ghq12_score w, i(block cr_id club treat treat_ther ) j(round)
*** drop +cash folks in longer follow ups 
drop if treat==2 & round>=2
tab round treat
*** Plot 
forvalues r=1/3 {
	if `r'==1 {
		local round = "Rapid Resurvey"
		local plot_note = "IPT-G and IPT-G+ groups are combined."
	} 
	else if `r'==2 {
		local round = "Midline"
		local plot_note = "Plot excludes the IPT-G+ group."
	} 
	else if `r'==3 {
		local round = "Endline"
		local plot_note = "Plot excludes the IPT-G+ group."
	}
	*** PHQ
	distplot phq8_score [aw=w] if round==`r', over(treat_ther) ///
		graphregion(color(white)) legend(rows(1) pos(6)) lc(green red) ///
		title("PHQ-8 Score at `round'")  ///
		note(`plot_note') 
	graph export "${figures}/cdf_phq8_iptg_r`r'.png", replace 
	*** GHQ
	distplot ghq12_score [aw=w] if round==`r', over(treat_ther) ///
		graphregion(color(white)) legend(rows(1) pos(6)) lc(green red) ///
		title("GHQ-12 Score at `round'") ///
		note(`plot_note')
	graph export "${figures}/cdf_ghq12_iptg_r`r'.png", replace 
}
*/

******* Compare therapy and cash 
use "${data}/Analysis_wide.dta", clear
distinct block club
keep phq8_score? ghq12_score? w? block cr_id club treat 
reshape long phq8_score ghq12_score w, i(block cr_id club treat ) j(round)
*** drop +cash folks in longer follow ups 
drop if treat==0 | round<2
tab round treat
*** Plot 
forvalues r=2/3 {
	if `r'==2 {
		local round = "Midline"
	} 
	else if `r'==3 {
		local round = "Endline"
	}
	*** PHQ
	distplot phq8_score [aw=w] if round==`r', over(treat) ///
		graphregion(color(white)) legend(rows(1) pos(6)) lc(red blue) ///
		title("PHQ-8 Score at `round'") 
	graph export "${figures}/cdf_phq8_cash_r`r'.png", replace 
	*** GHQ
	distplot ghq12_score [aw=w] if round==`r', over(treat) ///
		graphregion(color(white)) legend(rows(1) pos(6)) lc(red blue) ///
		title("GHQ-12 Score at `round'")
	graph export "${figures}/cdf_ghq12_cash_r`r'.png", replace 
}

